<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/global/jsp-header.jsp"%>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html">
		<title>新增组别</title>
		<%@ include file="/global/html-header.jsp"%>
		<script>
	$(function() {
		$('.myform').idealforms();
		common.validator("groupform");
		$("#groupform").submit(function(){
			$("#groupId").removeAttr("disabled");
			var param=$(this).serialize();
			var canSubmit=common.checkBlankValue(param,new Array("group.groupId","group.groupName","group.disabled"));
			if(canSubmit){
				$.ajax({   
	        		type: "POST",  
	        		url: "${action }",  
	        		data: param, 
	        		success: function(msg){    
	        			window.parent.closeDialog();
		        		var alertMsg="";
	        			<c:if test="${addOperater}">
		        			if(msg=="success"){
		        				alertMsg="组别添加成功！";
		        				$(window.parent.document).find("#myform").submit();
		        			}else if(msg=="exists"){
	            				alertMsg="组别ID已存在！";
	            			}else{
	            				alertMsg="组别添加失败！";
	            			}
	        			</c:if>
	        			<c:if test="${updateOperater}">
		        			if(msg=="success"){
		                    	alertMsg="组别更新成功！";
		                    	$(window.parent.document).find("#myform").submit();
	            			}else if(msg=="nochange"){
	            				alertMsg="组别属性没有改变！";
	            			}else{
	            				alertMsg="组别更新失败！";
	            			}
	    				</c:if>
	        			window.parent.editGroupTip(alertMsg);
	        		} 
	        	});
			}
			return false;
		});
	});
</script>
	</head>
	<body>
		<form action="${action }" name="groupform" class="myform"
			id="groupform" method="post">
			<div>
				<label class="required">
					组别编号:
				</label>
				<input type="text" size="40" id="groupId" name="group.groupId"
					class="{required:true,digits:true,messages:{required:'请输入组别编号'}}" ${updateOperater ? 'disabled=true':''} value="${group.groupId }"/>
			</div>
			<div>
				<label class="required">
					组别名称:
				</label>
				<input type="text" size="40" name="group.groupName"
					class="{required:true,messages:{required:'请输入组别名称'}}" value="${group.groupName }"/>
			</div>
			<div>
				<label class="required">是否可用:</label>
				<select name="group.disabled" class="{required:true,messages:{required:'请输入组别是否可用'}}">
					<option value="">请选择</option>
					<option value="1" ${group.disabled eq 1 ? 'selected':'' }>可用</option>
					<option value="0" ${group.disabled eq 0 ? 'selected':'' }>不可用</option>
				</select>
			</div>
			<div>
				<label class="required">所属部门:</label>
				<c:if test="${not empty allDept }">
					<c:forEach items="${allDept }" var="item">
						<c:forEach items="${curDepts }" var="curItem">
							 <c:if test="${item.deptId eq curItem.deptId }">
							 	<c:set var="deptChecked" value="${true}"></c:set>
							 </c:if>
						</c:forEach>
						<label><input type="checkbox" name="deptIds" value="${item.deptId }" ${deptChecked ? "checked" : "" } />${item.deptName }</label>
						<c:set var="deptChecked" value="${false}"></c:set>
					</c:forEach>
				</c:if>
				<c:if test="${empty allDept }">
					<label>
					<select name="deptIds" class="{required:true,messages:{required:'请添加部门'}}">
						<option value="-1">无部门</option>
					</select>
					</label>
				</c:if>
			</div>
			<div>
				<label>
					&nbsp;
				</label>
				<input id="adddeptbtn" type="submit" value="${btnKeyWord }" />
			</div>
		</form>
	</body>
</html>